/****************************************************************
 *  This file created by writerB.php on 03/19/2007 at 11:51:15  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: reset.cpp
 *  Class Name: Reset
 *  Data members: 7
 *  Notes:
 ****************************************************************/

#include <iostream>
#include "definitions.h"
#include "log.h"
#include "reset.h"
#include "stringutil.h"



int Reset::numResets = 0;
int Reset::resetIndex = 0;


// Default constructor...
Reset::Reset() {
	setResetID( ++resetIndex );
	setVnum( 0 );
	setType( 0 );
	setTarget( 0 );
	setNumber( 0 );
	setLimit( 0 );
	setIn( 0 );
	setAt( 0 );
	// Increment the object count...
	numResets++;
}

// Additional constructors...

// Copy constructor (Doesn't change _ResetID)...
Reset::Reset( const Reset& ref ) {
	setResetID( ++resetIndex );
	setVnum( ref.getVnum() );
	setType( ref.getType() );
	setTarget( ref.getTarget() );
	setNumber( ref.getNumber() );
	setLimit( ref.getLimit() );
	setIn( ref.getIn() );
	setAt( ref.getAt() );
	// Increment the object count...
	numResets++;
}

// Destructor...
Reset::~Reset() {
	// Decrement the object count...
	numResets--;
}

// Assignment operator (Doesn't change _ResetID)...
Reset& Reset::operator = ( const Reset& ref ) {
	setVnum( ref.getVnum() );
	setType( ref.getType() );
	setTarget( ref.getTarget() );
	setNumber( ref.getNumber() );
	setLimit( ref.getLimit() );
	setIn( ref.getIn() );
	setAt( ref.getAt() );
	return *this;
}

// Equality operator (Compares _vnum)...
bool Reset::operator == ( const Reset& ref ) const {
	return ( getVnum() == ref.getVnum() );
}

// Inequality operator (Compares _vnum)...
bool Reset::operator != ( const Reset& ref ) const {
	return ( getVnum() != ref.getVnum() );
}

// Less than operator (Compares _vnum)...
bool Reset::operator < ( const Reset& ref ) const {
	return ( getVnum() < ref.getVnum() );
}

// Greater than operator (Compares _vnum)...
bool Reset::operator > ( const Reset& ref ) const {
	return ( getVnum() > ref.getVnum() );
}

// Protected Methods...
void Reset::setResetID( const int& ResetID ) {
	_ResetID = ResetID;
}

// Public accessor methods...
int Reset::getResetID( void ) const {
	return _ResetID;
}

void Reset::setVnum( const unsigned& vnum ) {
	// _vnum is non-negative...
	_vnum = ( vnum >= 0 ) ? vnum : 0;
	return;
}

unsigned Reset::getVnum( void ) const {
	return _vnum;
}

void Reset::setType( const unsigned& type ) {
	_type = type;
	return;
}

unsigned Reset::getType( void ) const {
	return _type;
}

void Reset::setTarget( const unsigned& target ) {
	// _target is non-negative...
	_target = ( target >= 0 ) ? target : 0;
	return;
}

unsigned Reset::getTarget( void ) const {
	return _target;
}

void Reset::setNumber( const unsigned& number ) {
	// _number is non-negative...
	_number = ( number >= 0 ) ? number : 0;
	return;
}

unsigned Reset::getNumber( void ) const {
	return _number;
}

void Reset::setLimit( const unsigned& limit ) {
	// _limit is non-negative...
	_limit = ( limit >= 0 ) ? limit : 0;
	return;
}

unsigned Reset::getLimit( void ) const {
	return _limit;
}

void Reset::setIn( const unsigned& in ) {
	// _in is non-negative...
	_in = ( in >= 0 ) ? in : 0;
	return;
}

unsigned Reset::getIn( void ) const {
	return _in;
}

void Reset::setAt( const unsigned& at ) {
	// _at is non-negative...
	_at = ( at >= 0 ) ? at : 0;
	return;
}

unsigned Reset::getAt( void ) const {
	return _at;
}

// General methods...
char Reset::type2char( void ) const {
	switch ( getType() ) {
		case MOB:		return 'M';
		case OBJECT:	return 'O';
		default:
			std::string message;
			message << "Default hit in Reset::type2char() in " << __FILE__ << " line " << __LINE__;
			log( message, SERVER );
			return '-';
	}
}

// Static methods...
unsigned Reset::string2type( const std::string& type ) {
	if ( type == "o" || type == "O" )
		return OBJECT;
	else if ( type == "m" || type == "M" )
		return MOB;
	else
		return -1;
}

// Associated operators...
std::ostream& operator << ( std::ostream& write, Reset& reset ) {
	write	<< "\n**RESET\n"
			<< reset.getVnum() << ' '
			<< reset.getType() << ' '
			<< reset.getTarget() << ' '
			<< reset.getNumber() << ' '
			<< reset.getLimit() << '\n';
	return write;
}

std::ostream& operator << ( std::ostream& write, Reset* reset ) {
	return ( write << *reset );
}

std::istream& operator >> ( std::istream& read, Reset& reset ) {
	unsigned vnum = 0, type = 0, target = 0, number = 0, limit = 0;
	read >> vnum >> type >> target >> number >> limit;
	reset.setVnum( vnum );
	reset.setType( type );
	reset.setTarget( target );
	reset.setNumber( number );
	reset.setLimit( limit );
	return read;
}

std::istream& operator >> ( std::istream& read, Reset* reset ) {
	return ( read >> *reset );
}
